package com.lagou.balance.impl;

import com.lagou.balance.LoadBalanceStrategy;
import com.lagou.server.RpcClient;

import java.util.List;
import java.util.Map;

public abstract class AbstractLoadBalanceStrategy implements LoadBalanceStrategy {

    /**
     * 路由方法由抽象类定义
     * @param clientPool
     * @param serverClassName
     * @return
     */
    @Override
    public RpcClient route(Map<String, List<RpcClient>> clientPool, String serverClassName) {
        List<RpcClient> rpcClients = clientPool.get(serverClassName);
        if(null == rpcClients) return null;
        return doSelect(rpcClients);
    }

    /**
     * 具体选择方法由实现类决定
     * @return
     * @param rpcClients
     */
    protected abstract RpcClient doSelect(List<RpcClient> rpcClients);
}
